# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: ScrumpyJack <scrumpyjack@st.ilet.to>
# Contributor: Miles Alan <m@milesalan.com>
# Maintainer: ScrumpyJack <scrumpyjack@st.ilet.to>
pkgname=netsurf
pkgver=3.11
pkgrel=0
pkgdesc="free, open source web browser"
url="http://www.netsurf-browser.org"
arch="all"
license="GPL-2.0-or-later"
makedepends="curl-dev openssl-dev doxygen flex bison libwebp-dev lcms2-dev
	libmng-dev gperf gtk+3.0-dev libcurl libpng-dev libidn-dev
	check-dev libharu-dev librsvg-dev libjpeg-turbo-dev vim
	perl perl-html-parser sdl12-compat-dev expat-dev"
subpackages="
	$pkgname-doc
	$pkgname-framebuffer
	$pkgname-framebuffer-doc
"
source="http://download.netsurf-browser.org/netsurf/releases/source-full/netsurf-all-$pkgver.tar.gz
	netsurf
	non-coreutils-install-compatibility.patch"

builddir="$srcdir"/$pkgname-all-$pkgver

export CFLAGS="$CFLAGS -fcommon"

prepare() {
	default_prepare
	sed 's:-Werror::' -i "$builddir"/libsvgtiny/Makefile
}

build() {
	make \
		TARGET=gtk3 \
		LIBDIR=lib \
		INCLUDEDIR=include \
		PREFIX=/usr

	make \
		TARGET=framebuffer \
		LIBDIR=lib \
		INCLUDEDIR=include \
		PREFIX=/usr
}

package() {
	make \
		TARGET=gtk3 \
		LIBDIR=lib \
		INCLUDEDIR=include \
		DESTDIR="$pkgdir" \
		PREFIX=/usr \
		install

	install -Dm755 "$srcdir/netsurf" "$pkgdir/usr/bin/$pkgname"
	install -Dm644 netsurf/docs/netsurf-gtk.1 -t "$pkgdir"/usr/share/man/man1

	# Icon
	install -Dm644 netsurf/frontends/gtk/res/netsurf.xpm \
		"$pkgdir"/usr/share/pixmaps/netsurf.xpm

	# Desktop file
	install -Dm644 netsurf/frontends/gtk/res/netsurf-gtk.desktop \
		"$pkgdir"/usr/share/applications/netsurf.desktop

	# Run netsurf, not netsurf-gtk
	sed \
		-e 's:netsurf-gtk:netsurf:g' \
		-e 's:netsurf.png:netsurf:g' \
		-i "$pkgdir"/usr/share/applications/netsurf.desktop
}

framebuffer() {
	pkgdesc="$pkgdesc (framebuffer)"

	cd "$builddir"
	make \
		TARGET=framebuffer \
		LIBDIR=lib \
		INCLUDEDIR=include \
		PREFIX=/usr \
		DESTDIR="$subpkgdir" \
		install

	install -Dm755 netsurf/nsfb "$subpkgdir/usr/bin/netsurf-framebuffer"
	install -Dm644 netsurf/docs/netsurf-fb.1 -t "$pkgdir"/usr/share/man/man1
}

sha512sums="
f931687e08976ca336762587cc1ac75e45518be62b19d1d31aac3063b92b9666f8a022ff3a183e80c89404ba8ff33458b26521130e96943043085a42291ee283  netsurf-all-3.11.tar.gz
4f6868f377abb1fbade92088bee9a319952c4cee82821ca5b3f892484e0d111f33045c8583f3d069e48af6f3f2fcad43c364daa0f5457b3b013542793ac10fcf  netsurf
528a0d085afcf089789fc2e2aafa27e48c71f9eba1eeed65ba293ccb9c60187193d8e36337ff56b9de8221821d6cb2a4146e175edb383f7a6ef660771c8a1e28  non-coreutils-install-compatibility.patch
"
